package com.etc.medical.feign;

import com.etc.common.utils.Result;
import com.etc.drug.entity.Drug;
import com.etc.medical.client.DrugClient;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author 29322
 */
@RestController
@RequestMapping("/drug")
@CrossOrigin(origins = "*")
public class DrugFeign {

    @Resource
    private DrugClient drugClient;

    /**
     * 查询药品类目
     */
    @RequestMapping("/queryCategory")
    public Result queryCategory(@RequestParam("pageNum") Integer pageNum,
                                @RequestParam("pageSize") Integer pageSize) {
        return drugClient.queryCategory(pageNum, pageSize);
    }

    /**
     * 新增药品类目
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public Result insert(@RequestBody Drug drug) {
        return drugClient.insert(drug);
    }

    /**
     * 修改药品类目
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Result update(@RequestBody Drug drug) {
        return drugClient.update(drug);
    }

    /**
     * 根据处方Id查询药品出库信息
     */
    @RequestMapping("/queryByPId")
    public Result queryByPId(@RequestParam("prescriptionId") String prescriptionId) {
        return drugClient.queryByPId(prescriptionId);
    }

    /**
     * 查询药品库存
     */
    @RequestMapping("/queryStorage")
    public Result queryDrugNum(@RequestParam("pageNum") Integer pageNum,
                               @RequestParam("pageSize") Integer pageSize) {
        return drugClient.queryDrugNum(pageNum, pageSize);
    }

    /**
     * 药品进货
     */
    @RequestMapping(value = "/storage", method = RequestMethod.POST)
    public Result storage(@RequestParam("drugId") String drugId,
                          @RequestParam("drugPack") Integer drugPack,
                          @RequestParam("drugValidity") @DateTimeFormat(pattern = "yyyy-MM-dd") Date drugValidity,
                          @RequestParam("storageNum") Integer storageNum,
                          @RequestParam("operatorId") String operatorId) {
        return drugClient.storage(drugId, drugPack, drugValidity, storageNum, operatorId);
    }

    /**
     * 医生开处方添加药品
     */
    @RequestMapping(value = "/outbound", method = RequestMethod.POST)
    public Result outbound(@RequestParam("prescriptionId") String prescriptionId,
                           @RequestParam("drugId") String drugId,
                           @RequestParam("drugValidity") @DateTimeFormat(pattern = "yyyy-MM-dd") Date drugValidity,
                           @RequestParam("outboundNum") Integer outboundNum,
                           @RequestParam("operatorId") String operatorId) {
        return drugClient.outbound(prescriptionId, drugId, drugValidity, outboundNum, operatorId);
    }

    /**
     * 药品出库
     */
    @RequestMapping(value = "/updateStatue", method = RequestMethod.POST)
    public Result updateStatue(@RequestParam("outboundId") String outboundId,
                               @RequestParam("operatorId") String operatorId) {
        return drugClient.updateStatue(outboundId, operatorId);
    }
}
